/**
 * 
 * @Project HRL Simulation
 * @Date 20.06.2011
 * @Author Aebi Pascal, Kocher Marc, Sriranjan George
 * @School BFH-TI Biel, Projekt 1
 *
 */

package gui.objects3D;

import javax.media.j3d.Appearance;
import javax.media.j3d.LineArray;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.Shape3D;
import javax.vecmath.Point3f;

/**
 * The Class Conveyor3D.
 */
public class Conveyor3D extends Shape3D{

	
	/**
	 *  Instantiate a new Conveyor3D object.
	 * 
	 * @param points the calculated points for the 3D conveyor object
	 */
	public Conveyor3D(Point3f[] points){
		this.addGeometry(createGeometry(points));
		this.setAppearance(createAppearance());
	}

	
	/**
	 * Create the appearance.
	 * 
	 * @return the appearance
	 */
	private Appearance createAppearance() {
		Appearance app = new Appearance();
		PolygonAttributes polyAttr = new PolygonAttributes();
		polyAttr.setPolygonMode(PolygonAttributes.POLYGON_LINE);
		app.setPolygonAttributes(polyAttr);
		return app;
	}
	
	
	/**
	 * Create the geometry based on the calucated points.
	 * 
	 * @param points the calculated points for the 3D conveyor object
	 * @return the line array
	 */
	private LineArray createGeometry(Point3f[] points){
		LineArray conveyor = new LineArray(16, LineArray.COORDINATES);
		
		// external border
		conveyor.setCoordinate(0, points[0]);
		conveyor.setCoordinate(1, points[1]);
		
		conveyor.setCoordinate(2, points[1]);
		conveyor.setCoordinate(3, points[2]);
		
		conveyor.setCoordinate(4, points[2]);
		conveyor.setCoordinate(5, points[3]);
		
		conveyor.setCoordinate(6, points[3]);
		conveyor.setCoordinate(7, points[0]);
		
		// internal border
		conveyor.setCoordinate(8, points[4]);
		conveyor.setCoordinate(9, points[5]);
		
		conveyor.setCoordinate(10, points[5]);
		conveyor.setCoordinate(11, points[6]);
		
		conveyor.setCoordinate(12, points[6]);
		conveyor.setCoordinate(13, points[7]);
		
		conveyor.setCoordinate(14, points[7]);
		conveyor.setCoordinate(15, points[4]);
		
		return conveyor;
	}

}